package com.ssy.lingxi.platform.manage.controller.content;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.manage.entity.content.ContentNotice;
import com.ssy.lingxi.platform.manage.model.request.common.CommonIdRequest;
import com.ssy.lingxi.platform.manage.model.request.common.CommonStatusRequest;
import com.ssy.lingxi.platform.manage.model.request.content.ContentNoticePageRequest;
import com.ssy.lingxi.platform.manage.model.request.content.ContentNoticeRequest;
import com.ssy.lingxi.platform.manage.model.response.ContentNoticeResponse;
import com.ssy.lingxi.platform.manage.service.content.IContentNoticeService;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author fhj
 * @version 2.0.0
 * @menu 内容管理 - 公告管理
 * @date 2020/9/17
 */
@Api(tags = "内容管理 - 公告管理")
@RestController
@RequestMapping("/manage/contentNotice")
public class ContentNoticeController extends BaseController {

    @Resource
    private IContentNoticeService contentNoticeService;

    /**
     * 列表
     *
     * @param request 请求参数
     * @return 操作结果
     */
    @GetMapping("/page")
    public Wrapper<PageData<ContentNotice>> page(@Valid ContentNoticePageRequest request) {
        return contentNoticeService.page(request);
    }

    /**
     * 详情
     *
     * @param request 请求参数
     * @return 操作结果
     */
    @GetMapping(value = "/get")
    public Wrapper<ContentNotice> get(@Validated CommonIdRequest request) {
        return contentNoticeService.get(request);
    }

    /**
     * 新增
     *
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/add")
    public Wrapper<Void> add(@RequestBody @Validated({ContentNoticeRequest.Add.class}) ContentNoticeRequest request) {
        return contentNoticeService.add(request, getSysUser());
    }

    /**
     * 修改
     *
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> update(@RequestBody @Validated({ContentNoticeRequest.Update.class}) ContentNoticeRequest request) {
        return contentNoticeService.update(request, getSysUser());
    }

    /**
     * 上架/下架
     *
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/updateStatus")
    public Wrapper<Void> updateStatus(@RequestBody @Validated({CommonStatusRequest.Shelf.class}) CommonStatusRequest request) {
        return contentNoticeService.updateStatus(request, getSysUser());
    }

    /**
     * 删除
     *
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/delete")
    public Wrapper<Void> delete(@RequestBody @Validated CommonIdRequest request) {
        return contentNoticeService.delete(request, getSysUser());
    }

    /**
     * 根据栏目获取所有
     *
     * @param columnType 栏目类型
     * @return 操作结果
     */
    @GetMapping(value = "/findAllByColumnType")
    public Wrapper<List<ContentNotice>> findAllByColumnType(Integer columnType) {
        return contentNoticeService.findAllByColumnType(columnType);
    }

    /**
     * 根据栏目获取所有(不返回context字段内容)
     *
     * @param columnType 栏目类型
     * @return 操作结果
     */
    @GetMapping(value = "/findWithOutContent")
    public Wrapper<List<ContentNoticeResponse>> findWithOutContent(Integer columnType) {
        return contentNoticeService.findWithOutContent(columnType);
    }

    /**
     * 获取最新公告
     *
     * @param pageVO 分页参数
     * @return 操作结果
     */
    @GetMapping(value = "/findNewestNotice")
    public Wrapper<PageData<ContentNotice>> findNewestNotice(@Valid PageVO pageVO) {
        return contentNoticeService.findNewestNotice(pageVO);
    }
}
